package com.example.demo.controller;

import com.example.demo.common.enums.TagStatusEnum;
import com.example.demo.controller.vo.BaseResponse;
import com.example.demo.entity.TagEntity;
import com.example.demo.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TagContorller {

    @Autowired
    private TagService tagService;

    @GetMapping("/tag")
    public BaseResponse<List<TagEntity>> queryTagList(Long tagId, String tagName) {
        BaseResponse<List<TagEntity>> successResult = BaseResponse.getSuccessResult(BaseResponse.class);
        List<TagEntity> tagEntities = tagService.queryTagList(tagId, tagName);
        successResult.setData(tagEntities);
        return successResult;
    }

    @PostMapping("/tag")
    public BaseResponse insertTag(@RequestBody TagEntity tagEntity) {
        BaseResponse successResult = BaseResponse.getSuccessResult(BaseResponse.class);
        tagEntity.setStatus(TagStatusEnum.USE.getCode());
        Integer response = tagService.insertTag(tagEntity);
        if (response == 1) {
            successResult.setData(1);
        }else {
            successResult.setData(0);
        }
        return successResult;
    }
}